package com.villaday.idf.activity;


import androidx.annotation.IdRes;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.appcompat.widget.Toolbar;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.villaday.idf.R;
import com.villaday.idf.adapter.VipIncomeListAdapter;
import com.villaday.idf.base.AbsRecyclerViewAdapter;
import com.villaday.idf.base.BaseActivity;
import com.villaday.idf.base.BaseFragment;
import com.villaday.idf.base.OnAdapterCallbackListener;
import com.villaday.idf.custom.CustomHeaderAndFooterPicker;
import com.villaday.idf.custom.LoadingDialog;
import com.villaday.idf.custom.DividerItemDecoration.RVItemDecoration;
import com.villaday.idf.custom.ViewPagerSlide;
import com.villaday.idf.fragment.ChartVPFragment;
import com.villaday.idf.fragment.ChartWeeklyVPFragment;
import com.villaday.idf.model.RecommendEntity;
import com.villaday.idf.model.VipsMemberOrders;
import com.villaday.idf.model.saleHouseEntity;
import com.villaday.idf.util.Constant;
import com.villaday.idf.util.DateUtils;
import com.villaday.idf.util.LogeUtil;
import com.villaday.idf.util.OkHttpUtil;
import com.villaday.idf.util.PhoneUtil;
import com.villaday.idf.util.ToolBarUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.Unbinder;
import luojie.hnulab.librarydemo.picker.DatePicker;

/**
 * Vip模块收益详情
 */
public class IncomeDetailsActivity extends BaseActivity implements SwipeRefreshLayout.OnRefreshListener, AbsRecyclerViewAdapter.OnItemClickListener, View.OnClickListener, OnAdapterCallbackListener, OkHttpUtil.OnDataListener
        , RadioGroup.OnCheckedChangeListener, CustomHeaderAndFooterPicker.OnCancelDateTimeListiner {

    @BindView(R.id.toolbar_text)
    Toolbar toolbar;
    @BindView(R.id.rv)
    RecyclerView rv;
    @BindView(R.id.srl)
    SwipeRefreshLayout srl;
    Unbinder unbinder;
    private LoadingDialog loadingDialog;
    private Gson gson = new GsonBuilder().create();

    private int pageNo = 1;
    private int nextIndex = 1;
    private int pageSize = 20;
    List<RecommendEntity.BodyEntity.DataListEntity> data = new ArrayList();
    private VipIncomeListAdapter vipIncomeListAdapter;

    public LinearLayout llSaleLayout;
    public LinearLayout llBalanceLayout;
    public TextView tvTiteleOne;
    public TextView tvTiteleTwo;
    public TextView tvTiteleThree;

    public TextView tvSaleOne, tvSaleTwo, tvSaleThree;
    public TextView tvBalaneOne, tvBalaneTwo, tvBalaneThree;

    public LinearLayout llSourceOrderLayout;
    public TextView tvUnSourceOrder;
    public TextView tvWeekMonthTitle;


    public LinearLayout llWeeklyLayout;
    public LinearLayout llWeeklySaleLayout;
    public LinearLayout llWeeklyBalanceLayout;
    public TextView tvWeeklyTiteleOne;
    public TextView tvWeeklyTiteleTwo;
    public TextView tvWeeklyTiteleThree;

    public TextView tvWeeklySaleOne, tvWeeklySaleTwo, tvWeeklySaleThree;
    public TextView tvWeeklyBalaneOne, tvWeeklyBalaneTwo, tvWeeklyBalaneThree;


    public RadioGroup radioGroup;
    public TextView tvMonth;
    public TextView tvYear;
    public TextView tvIncome;
    public ViewPagerSlide viewPagerSlide;
    private List<BaseFragment> fragmentList = new ArrayList<>();

    public RadioGroup radioIndication;
    private int saleStatus = 1;
    private List<saleHouseEntity.BodyBean.ListBean> houseList = new ArrayList<>();


    private String beginDateTime = "";
    private String endDateTime = "";

    private String salebeginDate = "";
    private String saleEndDate = "";
    List<VipsMemberOrders.BodyBean.ListBean> detailsList = new ArrayList();
    private TextView tvStartTime;
    private TextView tvEndTime;

    private String currentYear, currentMonth, currentDay;
    private int startYear = 2018;
    private int startMonth = 1;
    private int startDay = 1;

    @Override
    protected int getViewResId() {
        return R.layout.activity_income_details;
    }

    @Override
    protected void init() {
        ToolBarUtil.init(toolbar, "收益详情", new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onBackPressed();
            }
        });
        srl.setOnRefreshListener(this);
        rv.setLayoutManager(new LinearLayoutManager(this));
        vipIncomeListAdapter = new VipIncomeListAdapter(this, this, this);
        rv.setAdapter(vipIncomeListAdapter);

        rv.addItemDecoration(new RVItemDecoration(LinearLayout.VERTICAL, PhoneUtil.dp2px(this, 1), getResources().getColor(R.color.colorBg), PhoneUtil.dp2px(this, 8)));
        vipIncomeListAdapter.setOnItemClickListener(this);
        View inflate = View.inflate(this, R.layout.item_head_income_details, null);
        vipIncomeListAdapter.addHeaderView(inflate);
        vipIncomeListAdapter.setEmptyView(R.layout.empty_tips);
        vipIncomeListAdapter.setEmptyTips(R.id.tv_emptyTips, "没有更多了");
        initView(inflate);
        String[] Date = DateUtils.GetNowDate().split("-");
        currentYear = Date[0];
        currentMonth = Date[1];
        currentDay = Date[2];
//        beginDateTime = DateUtils.getdate(-30) + " 00:00:00";
//        endDateTime = DateUtils.GetNowDate() + " 00:00:00";
//        tvStartTime.setText(DateUtils.getdate(-30));
//        tvEndTime.setText(DateUtils.GetNowDate());
        LogeUtil.e("loge", currentYear + "*" + currentMonth + "*" + currentDay);
        loadingDialog = LoadingDialog.newInstance("加载中...");
        loadingDialog.show(getFragmentManager());

        tvMonth.setText(currentYear + "年" + currentMonth + "月");

        /**
         * 获取本月时间
         */
//        beginDateTime = DateUtils.getMinMonthDate(DateUtils.GetNowDate()) + " 00:00:00";
//        salebeginDate = DateUtils.getMinMonthDate(DateUtils.GetNowDate()) + " 00:00:00";
//        endDateTime = DateUtils.getMaxMonthDate(DateUtils.GetNowDate()) + " 23:59:59";
        LogeUtil.e("loge", salebeginDate + "^^" + endDateTime);

    }

    private void initView(View headView) {
        tvTiteleOne = (TextView) headView.findViewById(R.id.tv_name_one);
        tvTiteleTwo = (TextView) headView.findViewById(R.id.tv_name_two);
        tvTiteleThree = (TextView) headView.findViewById(R.id.tv_name_three);

        llSaleLayout = (LinearLayout) headView.findViewById(R.id.ll_sale_layout);
        llBalanceLayout = (LinearLayout) headView.findViewById(R.id.ll_balance_layout);


        tvSaleOne = (TextView) headView.findViewById(R.id.tv_sale_one);
        tvSaleTwo = (TextView) headView.findViewById(R.id.tv_sale_two);
        tvSaleThree = (TextView) headView.findViewById(R.id.tv_sale_three);
        tvBalaneOne = (TextView) headView.findViewById(R.id.tv_balance_one);
        tvBalaneTwo = (TextView) headView.findViewById(R.id.tv_balance_two);
        tvBalaneThree = (TextView) headView.findViewById(R.id.tv_balance_three);


        llWeeklyLayout = (LinearLayout) headView.findViewById(R.id.ll_weekly_data_order);
        llWeeklySaleLayout = (LinearLayout) headView.findViewById(R.id.ll_weekly_sale_layout);
        llWeeklyBalanceLayout = (LinearLayout) headView.findViewById(R.id.ll_weekly_balance_layout);

        tvWeeklyTiteleOne = (TextView) headView.findViewById(R.id.tv_weekly_name_one);
        tvWeeklyTiteleTwo = (TextView) headView.findViewById(R.id.tv_weekly_name_two);
        tvWeeklyTiteleThree = (TextView) headView.findViewById(R.id.tv_weekly_name_three);

        tvWeeklySaleOne = (TextView) headView.findViewById(R.id.tv_weekly_sale_one);
        tvWeeklySaleTwo = (TextView) headView.findViewById(R.id.tv_weekly_sale_two);
        tvWeeklySaleThree = (TextView) headView.findViewById(R.id.tv_weekly_sale_three);
        tvWeeklyBalaneOne = (TextView) headView.findViewById(R.id.tv_weekly_balance_one);
        tvWeeklyBalaneTwo = (TextView) headView.findViewById(R.id.tv_weekly_balance_two);
        tvWeeklyBalaneThree = (TextView) headView.findViewById(R.id.tv_weekly_balance_three);


        radioGroup = (RadioGroup) headView.findViewById(R.id.rb_date);
        tvMonth = (TextView) headView.findViewById(R.id.tv_month);
        tvYear = (TextView) headView.findViewById(R.id.tv_year);
        tvIncome = (TextView) headView.findViewById(R.id.tv_income);
        viewPagerSlide = (ViewPagerSlide) headView.findViewById(R.id.vp_chart);
        fragmentList.add(ChartVPFragment.newInstance());
        fragmentList.add(ChartWeeklyVPFragment.newInstance());
        viewPagerSlide.setAdapter(new RecommendVPAdapter(getSupportFragmentManager()));




        radioIndication = (RadioGroup) headView.findViewById(R.id.rb_indication);
        radioIndication.setOnCheckedChangeListener(this);

        tvStartTime = (TextView) headView.findViewById(R.id.start_time);
        tvEndTime = (TextView) headView.findViewById(R.id.end_time);


        llSourceOrderLayout = (LinearLayout) headView.findViewById(R.id.ll_data_order);
        tvUnSourceOrder = (TextView) headView.findViewById(R.id.tv_empty_order);
        tvWeekMonthTitle = (TextView) headView.findViewById(R.id.tv_week_month_layout);


        tvTiteleOne.setOnClickListener(this);
        tvTiteleTwo.setOnClickListener(this);
        tvTiteleThree.setOnClickListener(this);
        tvYear.setText(DateUtils.getYear() + "年");
        tvYear.setOnClickListener(this);
        tvMonth.setOnClickListener(this);
        tvIncome.setText("总收益：¥" + getIntent().getStringExtra("income"));
        tvStartTime.setOnClickListener(this);
        tvEndTime.setOnClickListener(this);

        radioGroup.setOnCheckedChangeListener(this);
        //默认选择周
        viewPagerSlide.setCurrentItem(1);
        tvYear.setVisibility(View.GONE);
        tvMonth.setVisibility(View.VISIBLE);
        salebeginDate = DateUtils.getCurrentMonday();
        saleEndDate = DateUtils.getPreviousSunday() + " 23:59:59";
        tvWeekMonthTitle.setText("本周最畅销");
    }

    @Override
    protected void loadData() {
        requestHouse();
        getData();
    }

    private void getData() {
        Map<String, String> map = new HashMap<>();
        map.put("pageNo", pageNo + "");
        map.put("pageSize", pageSize + "");
        map.put("vipOrderType", "0");
        map.put("methodType", "1");
        if (!TextUtils.isEmpty(beginDateTime))
            map.put("beginDateTime", beginDateTime);
        if (!TextUtils.isEmpty(endDateTime))
            map.put("endDateTime", endDateTime);
        OkHttpUtil.getJSON(this, Constant.URL.vips_member_orders, map, this);
    }


    @Override
    public void onRefresh() {
        pageNo = 1;
        nextIndex = 1;
        getData();
        requestHouse();
    }

    //rv item 点击事件
    @Override
    public void onItemClick(View v, int position) {
/*        Intent intent = new Intent(this, FindDetailsActivity.class);
        intent.putExtra("topicId", data.get(position).getId());
        startActivity(intent);*/
    }

    @Override//rv 里面控件  喜欢和分享
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_name_one: {
            }
            break;
            case R.id.tv_name_two: {

            }
            break;
            case R.id.tv_name_three: {

            }
            break;

            case R.id.tv_year: {
                onYearPicker();
            }
            break;

            case R.id.tv_month: {
                onYearMonthPicker();
            }
            break;

            case R.id.start_time: {
                onStartYearMonthDayPicker();
            }
            break;

            case R.id.end_time: {
                onStartYearMonthDayPicker();
            }
            break;
        }
    }

    @Override
    public void onCallback() {
        if (nextIndex == pageNo + 1) {
            pageNo++;
            getData();
        }
    }

    @Override
    public void onResponse(String url, String json) {
        if (!TextUtils.isEmpty(json)) {
            if (Constant.URL.vips_member_orders.equals(url)) {
                LogeUtil.e("vips_member_orders", json);
                dismissLoading();

                VipsMemberOrders recommendEntity = gson.fromJson(json, VipsMemberOrders.class);
                removeLoadingItem();
                if (pageNo == 1) {
                    detailsList.clear();
                }

                if ("200".equals(recommendEntity.getCode())) {
                   /* if (pageNo == 1 && presellEntity.getBody().getRecomendList() != null && presellEntity.getBody().getRecomendList().getList() != null) {

                        dataHead.addAll(presellEntity.getBody().getRecomendList().getList());
                        homeListSaleHeadAdapter.setData(dataHead);
                    }*/
                    detailsList.addAll(recommendEntity.getBody().getList());
                    if (recommendEntity.getBody().isHasNext()) {
                        detailsList.add(new VipsMemberOrders.BodyBean.ListBean(1));
                        nextIndex = pageNo + 1;

                    } else {
                        addBaseLine();
                    }

                } else {
                    addBaseLine();
                }
                vipIncomeListAdapter.setData(detailsList);
            } else if (Constant.URL.selling.equals(url)) {
                LogeUtil.e("selling", json);
                saleHouseEntity she = gson.fromJson(json, saleHouseEntity.class);
                if ("200".equals(she.getCode())) {
                    houseList.clear();
                    houseList.addAll(she.getBody().getList());
                    UpdateHouseSource(houseList);
                }
            }
        }
    }

    @Override
    public void onFailure(String url, String error) {

    }

    private void dismissLoading() {

        if (srl != null && srl.isRefreshing()) {
            srl.setRefreshing(false);
        }

        if (loadingDialog != null) {
            loadingDialog.dismiss();
        }

    }

    private void removeLoadingItem() {
        if (detailsList.size() > 0) {
            if (detailsList.get(detailsList.size() - 1).getMyType() == 1) {
                detailsList.remove(detailsList.size() - 1);
            }
        }
    }

    private void addBaseLine() {
        if (pageNo != 1) {
            detailsList.add(new VipsMemberOrders.BodyBean.ListBean(2));
        }
    }

    @Override
    public void onCheckedChanged(RadioGroup radioGroup, @IdRes int i) {
        switch (i) {
            case R.id.rb_month: {
                viewPagerSlide.setCurrentItem(0);
                tvYear.setVisibility(View.VISIBLE);
                tvMonth.setVisibility(View.GONE);
                ((ChartVPFragment) fragmentList.get(0)).onRefresh();


                salebeginDate = DateUtils.getMinMonthDate(DateUtils.GetNowDate());
                saleEndDate = DateUtils.getMaxMonthDate(DateUtils.GetNowDate()) + " 23:59:59";
                tvWeekMonthTitle.setText("本月最畅销");
                requestHouse();
                break;
            }

            case R.id.rb_weekly: {
                viewPagerSlide.setCurrentItem(1);
                tvYear.setVisibility(View.GONE);
                tvMonth.setVisibility(View.VISIBLE);
                ((ChartWeeklyVPFragment) fragmentList.get(1)).onRefresh();


                salebeginDate = DateUtils.getCurrentMonday();
                saleEndDate = DateUtils.getPreviousSunday() + " 23:59:59";
                tvWeekMonthTitle.setText("本周最畅销");
                requestHouse();
                break;
            }


            case R.id.rb_sale: {
                saleStatus = 1;
                requestHouse();
                llSaleLayout.setVisibility(View.VISIBLE);
                llBalanceLayout.setVisibility(View.GONE);
                llWeeklySaleLayout.setVisibility(View.VISIBLE);
                llWeeklyBalanceLayout.setVisibility(View.GONE);
                break;
            }

            case R.id.rb_balance: {
                saleStatus = 2;
                requestHouse();
                llSaleLayout.setVisibility(View.GONE);
                llBalanceLayout.setVisibility(View.VISIBLE);
                llWeeklySaleLayout.setVisibility(View.GONE);
                llWeeklyBalanceLayout.setVisibility(View.VISIBLE);
                break;
            }
        }
    }


    /**
     * 图表功能实现
     */

    class RecommendVPAdapter extends FragmentPagerAdapter {

        public RecommendVPAdapter(FragmentManager fm) {
            super(fm);

        }

        @Override
        public Fragment getItem(int position) {

            return fragmentList.get(position);
        }

        @Override
        public int getCount() {
            return 2;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return "";
        }
    }


    public void onYearPicker() {
        CustomHeaderAndFooterPicker picker = new CustomHeaderAndFooterPicker(this, DatePicker.YEAR);
        picker.setRangeStart(2018);
        picker.setRangeEnd(2029);
        picker.setSelectedItem(2018);
        picker.setGravity(Gravity.BOTTOM);
//                    picker.setDisplayPosition(findViewById(R.id.year),getTitleBarHeight());
        picker.setOnDatePickListener(new DatePicker.OnYearPickListener() {
            @Override
            public void onDatePicked(String year) {
                tvYear.setText(year + "年");
                ((ChartVPFragment) fragmentList.get(0)).onRefresh(year);
            }
        });
        picker.show();
    }


    public void onYearMonthPicker() {
        String currentDate = DateUtils.GetNowDate();
        String[] data = currentDate.split("-");
        CustomHeaderAndFooterPicker picker = new CustomHeaderAndFooterPicker(this, DatePicker.YEAR_MONTH);
        picker.setRangeStart(2018, 1);
        picker.setRangeEnd(Integer.parseInt(data[0]), Integer.parseInt(data[1]));
        picker.setSelectedItem(2018, 1);
        picker.setGravity(Gravity.BOTTOM);
//        picker.setDisplayPosition(findViewById(R.id.yearmonth),getTitleBarHeight());
        picker.setOnDatePickListener(new DatePicker.OnYearMonthPickListener() {

            @Override
            public void onDatePicked(String year, String month) {
                tvMonth.setText(year + "年" + month + "月");
                ((ChartWeeklyVPFragment) fragmentList.get(1)).onRefresh(year, month);
            }
        });
        picker.show();
    }


    /**
     * 本月最畅销
     */

    private void requestHouse() {
        Map<String, String> map = new HashMap<>();
        map.put("pageNo", "1");
        map.put("pageSize", "3");
        map.put("beginDateTime", salebeginDate);
        map.put("endDateTime", saleEndDate);
        map.put("orderType", saleStatus + "");
        OkHttpUtil.getJSON(this, Constant.URL.selling, map, this);
    }

    private void UpdateHouseSource(List<saleHouseEntity.BodyBean.ListBean> bean) {
        switch (radioGroup.getCheckedRadioButtonId()) {
            case R.id.rb_month: {
                switch (bean.size()) {
                    case 1: {
                        switch (radioIndication.getCheckedRadioButtonId()) {
                            case R.id.rb_sale:
                                tvSaleOne.setText(bean.get(0).getOrders() + "单");
                                tvSaleTwo.setText("");
                                tvSaleThree.setText("");
                                break;
                            case R.id.rb_balance:
                                tvBalaneOne.setText("+" + PhoneUtil.handleDecimal2((bean.get(0).getAmounts() / 100.0) + "") + "元");
                                tvBalaneTwo.setText("");
                                tvBalaneThree.setText("");
                                break;
                        }
                        tvTiteleOne.setText(bean.get(0).getHouse().getName());
                        tvTiteleTwo.setText("");
                        tvTiteleThree.setText("");

                        llSourceOrderLayout.setVisibility(View.VISIBLE);
                        llWeeklyLayout.setVisibility(View.GONE);
                        tvUnSourceOrder.setVisibility(View.GONE);
                        break;
                    }
                    case 2: {
                        switch (radioIndication.getCheckedRadioButtonId()) {
                            case R.id.rb_sale:
                                tvSaleOne.setText(bean.get(0).getOrders() + "单");
                                tvSaleTwo.setText(bean.get(1).getOrders() + "单");
                                tvSaleThree.setText("");
                                break;
                            case R.id.rb_balance:
                                tvBalaneOne.setText("+" + PhoneUtil.handleDecimal2((bean.get(0).getAmounts() / 100.0) + "") + "元");
                                tvBalaneTwo.setText("+" + PhoneUtil.handleDecimal2((bean.get(1).getAmounts() / 100.0) + "") + "元");
                                tvBalaneThree.setText("");
                                break;
                        }
                        tvTiteleOne.setText(bean.get(0).getHouse().getName());
                        tvTiteleTwo.setText(bean.get(1).getHouse().getName());
                        tvTiteleThree.setText("");

                        llSourceOrderLayout.setVisibility(View.VISIBLE);
                        llWeeklyLayout.setVisibility(View.GONE);
                        tvUnSourceOrder.setVisibility(View.GONE);
                        break;
                    }
                    case 3: {
                        switch (radioIndication.getCheckedRadioButtonId()) {
                            case R.id.rb_sale:
                                tvSaleOne.setText(bean.get(0).getOrders() + "单");
                                tvSaleTwo.setText(bean.get(1).getOrders() + "单");
                                tvSaleThree.setText(bean.get(2).getOrders() + "单");
                                break;
                            case R.id.rb_balance:
                                tvBalaneOne.setText("+" + PhoneUtil.handleDecimal2((bean.get(0).getAmounts() / 100.0) + "") + "元");
                                tvBalaneTwo.setText("+" + PhoneUtil.handleDecimal2((bean.get(1).getAmounts() / 100.0) + "") + "元");
                                tvBalaneThree.setText("+" + PhoneUtil.handleDecimal2((bean.get(2).getAmounts() / 100.0) + "") + "元");
                                break;
                        }
                        tvTiteleOne.setText(bean.get(0).getHouse().getName());
                        tvTiteleTwo.setText(bean.get(1).getHouse().getName());
                        tvTiteleThree.setText(bean.get(2).getHouse().getName());

                        llSourceOrderLayout.setVisibility(View.VISIBLE);
                        llWeeklyLayout.setVisibility(View.GONE);
                        tvUnSourceOrder.setVisibility(View.GONE);
                        break;
                    }

                    default: {
                        tvTiteleOne.setText("");
                        tvTiteleTwo.setText("");
                        tvTiteleThree.setText("");
                        tvBalaneOne.setText("");
                        tvBalaneTwo.setText("");
                        tvBalaneThree.setText("");
                        tvSaleOne.setText("");
                        tvSaleTwo.setText("");
                        tvSaleThree.setText("");
                        llSourceOrderLayout.setVisibility(View.INVISIBLE);
                        llWeeklyLayout.setVisibility(View.INVISIBLE);
                        tvUnSourceOrder.setVisibility(View.VISIBLE);
                        break;
                    }
                }
            }
            break;

            case R.id.rb_weekly: { //周
                switch (bean.size()) {
                    case 1: {
                        switch (radioIndication.getCheckedRadioButtonId()) {
                            case R.id.rb_sale:
                                tvWeeklySaleOne.setText(bean.get(0).getOrders() + "单");
                                tvWeeklySaleTwo.setText("");
                                tvWeeklySaleThree.setText("");
                                break;
                            case R.id.rb_balance:
                                tvWeeklyBalaneOne.setText("+" + PhoneUtil.handleDecimal2((bean.get(0).getAmounts() / 100.0) + "") + "元");
                                tvWeeklyBalaneTwo.setText("");
                                tvWeeklyBalaneThree.setText("");
                                break;
                        }
                        tvWeeklyTiteleOne.setText(bean.get(0).getHouse().getName());
                        tvWeeklyTiteleTwo.setText("");
                        tvWeeklyTiteleThree.setText("");
                        llSourceOrderLayout.setVisibility(View.GONE);
                        llWeeklyLayout.setVisibility(View.VISIBLE);
                        tvUnSourceOrder.setVisibility(View.GONE);
                        break;
                    }
                    case 2: {
                        switch (radioIndication.getCheckedRadioButtonId()) {
                            case R.id.rb_sale:
                                tvWeeklySaleOne.setText(bean.get(0).getOrders() + "单");
                                tvWeeklySaleTwo.setText(bean.get(1).getOrders() + "单");
                                tvWeeklySaleThree.setText("");
                                break;
                            case R.id.rb_balance:
                                tvWeeklyBalaneOne.setText("+" + PhoneUtil.handleDecimal2((bean.get(0).getAmounts() / 100.0) + "") + "元");
                                tvWeeklyBalaneTwo.setText("+" + PhoneUtil.handleDecimal2((bean.get(1).getAmounts() / 100.0) + "") + "元");
                                tvWeeklyBalaneThree.setText("");
                                break;
                        }
                        tvWeeklyTiteleOne.setText(bean.get(0).getHouse().getName());
                        tvWeeklyTiteleTwo.setText(bean.get(1).getHouse().getName());
                        tvWeeklyTiteleThree.setText("");

                        llSourceOrderLayout.setVisibility(View.GONE);
                        llWeeklyLayout.setVisibility(View.VISIBLE);
                        tvUnSourceOrder.setVisibility(View.GONE);
                        break;
                    }
                    case 3: {
                        switch (radioIndication.getCheckedRadioButtonId()) {
                            case R.id.rb_sale:
                                tvWeeklySaleOne.setText(bean.get(0).getOrders() + "单");
                                tvWeeklySaleTwo.setText(bean.get(1).getOrders() + "单");
                                tvWeeklySaleThree.setText(bean.get(2).getOrders() + "单");
                                break;
                            case R.id.rb_balance:
                                tvWeeklyBalaneOne.setText("+" + PhoneUtil.handleDecimal2((bean.get(0).getAmounts() / 100.0) + "") + "元");
                                tvWeeklyBalaneTwo.setText("+" + PhoneUtil.handleDecimal2((bean.get(1).getAmounts() / 100.0) + "") + "元");
                                tvWeeklyBalaneThree.setText("+" + PhoneUtil.handleDecimal2((bean.get(2).getAmounts() / 100.0) + "") + "元");
                                break;
                        }
                        tvWeeklyTiteleOne.setText(bean.get(0).getHouse().getName());
                        tvWeeklyTiteleTwo.setText(bean.get(1).getHouse().getName());
                        tvWeeklyTiteleThree.setText(bean.get(2).getHouse().getName());

                        llSourceOrderLayout.setVisibility(View.GONE);
                        llWeeklyLayout.setVisibility(View.VISIBLE);
                        tvUnSourceOrder.setVisibility(View.GONE);
                        break;
                    }

                    default: {
                        tvWeeklyTiteleOne.setText("");
                        tvWeeklyTiteleTwo.setText("");
                        tvWeeklyTiteleThree.setText("");
                        tvWeeklyBalaneOne.setText("");
                        tvWeeklyBalaneTwo.setText("");
                        tvWeeklyBalaneThree.setText("");
                        tvWeeklySaleOne.setText("");
                        tvWeeklySaleTwo.setText("");
                        tvWeeklySaleThree.setText("");
                        llSourceOrderLayout.setVisibility(View.INVISIBLE);
                        llWeeklyLayout.setVisibility(View.INVISIBLE);
                        tvUnSourceOrder.setVisibility(View.VISIBLE);
                        break;
                    }
                }
            }
            break;
        }

    }


    /**
     * 收益明细
     */

    //选择开始时间
    public void onStartYearMonthDayPicker() {
        CustomHeaderAndFooterPicker picker = new CustomHeaderAndFooterPicker(this, DatePicker.YEAR_MONTH_DAY, 1);
        picker.setRangeEnd(2029, 12, 30);
        picker.setRangeStart(2018, 1, 1);
        picker.setSelectedItem(Integer.parseInt(currentYear), Integer.parseInt(currentMonth), Integer.parseInt(currentDay));
        picker.setTopPadding(50);

        //设置滚轮条目数量（上下各2个） 默认是3
        picker.setOffset(2);
        //设置滚轮左右间隔
        picker.setPadding(19);
        //设置滚轮上下间隔
        picker.setLineSpaceMultiplier(2.6f);
        //设置位置在View下
//        picker.setDisplayPosition(findViewById(R.id.yearmonthday),getTitleBarHeight());
        picker.setGravity(Gravity.BOTTOM);
        picker.setOnCancelDateTimeListener(this);
        picker.setOnDatePickListener(new DatePicker.OnYearMonthDayPickListener() {
            @Override
            public void onDatePicked(String year, String month, String day) {
                startYear = Integer.parseInt(year);
                startMonth = Integer.parseInt(month);
                startDay = Integer.parseInt(day);
                onEndYearMonthDayPicker();
                tvStartTime.setText(year + "-" + month + "-" + day);
                beginDateTime = year + "-" + month + "-" + day + " 00:00:00";
            }
        });
        picker.show();
    }

    //选择结束时间
    public void onEndYearMonthDayPicker() {
        CustomHeaderAndFooterPicker picker = new CustomHeaderAndFooterPicker(this, DatePicker.YEAR_MONTH_DAY, 2);
        picker.setRangeEnd(2030, 12, 30);
        picker.setRangeStart(startYear, startMonth, startDay);
        picker.setSelectedItem(startYear, startMonth, startDay);
        picker.setTopPadding(50);

        //设置滚轮条目数量（上下各2个） 默认是3
        picker.setOffset(2);
        //设置滚轮左右间隔
        picker.setPadding(19);
        //设置滚轮上下间隔
        picker.setLineSpaceMultiplier(2.6f);
        //设置位置在View下
//        picker.setDisplayPosition(findViewById(R.id.yearmonthday),getTitleBarHeight());
        picker.setGravity(Gravity.BOTTOM);
        picker.setOnCancelDateTimeListener(this);
        picker.setOnDatePickListener(new DatePicker.OnYearMonthDayPickListener() {
            @Override
            public void onDatePicked(String year, String month, String day) {
                tvEndTime.setText(year + "-" + month + "-" + day);
                endDateTime = year + "-" + month + "-" + day + " 23:59:59";
                onRefresh();
            }
        });
        picker.show();
    }


    /**
     * 还原时间操作重新请求接口
     */
    @Override
    public void ReverseDateTime() {
        tvStartTime.setText("开始日期");
        tvEndTime.setText("结束日期");
        beginDateTime = "";
        endDateTime = "";
        onRefresh();
    }
}
